<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
    <script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>

    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
        <%if (UserUtil.isBankGroup()) {%>       
            $('#findGroupNoImg1').click(function() {
                $('#hidden\\.qryGroup\\.groupNo1').val('');
                $('#hidden\\.qryGroup\\.groupName1').val('');
                $('#qryGroup\\.groupNo1').val('');
                $('#qryGroup\\.groupName1').val('');
                $("#queryGroupResultDiv1").html('');
                
                $("#findGroupDiv1" ).dialog( "destroy" );
                $("#findGroupDiv1" ).dialog({  
                    title:'帳單業者查詢' 
                    , width: 600
                    , resizable: true
                    , modal: true
                });
            });
            
            $('#doAjaxQueryGroupsBtn1').click(function() {
                var groupNo = $('#qryGroup\\.groupNo1').val();
                var groupName = $('#qryGroup\\.groupName1').val();
                $("#queryGroupResultDiv1").html('');
    
                $('#hidden\\.qryGroup\\.groupNo1').val(groupNo);
                $('#hidden\\.qryGroup\\.groupName1').val(groupName);
                doQueryGroupAction1(1);
                
            });
    
            $('#doAjaxCloseGroupsBtn1').click(function() {
                $("#findGroupDiv1" ).dialog( "destroy" );
            });
        <%}%>
    });
    
    function doQueryGroupAction1(pageNumber)
    {
        $('#hidden\\.queryGroupResult\\.pageNumber1').val(pageNumber);
        $("#queryGroupResultDiv1").fadeTo("slow", 0.1);

        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
            async : true,
            type : 'POST',
            data : $("#queryGroupHiddenFrom1").serialize(),
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#queryGroupResultDiv1").html(data);
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                $("#ajaxErrorMessageDiv" ).dialog({  
                    title:'系統錯誤' 
                    ,width: 600
                    , resizable: false
                    , modal: true
                    , buttons: {
                        Ok: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
                },
            complete: function(XMLHttpRequest, textStatus){
                if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
                    $("#findGroupDiv1" ).dialog( "close" );
                    $("#findGroupDiv1" ).dialog( "open" );                   
                }
                closeWaitingDialog();
                $("#queryGroupResultDiv1").fadeTo("slow", 1);
            }
        });
    }        
    //-->
    </script>    
<c:choose>
    <c:when test="${null != actionBean.resultPayer}">
        <div id="addPayerViewDiv">
            <stripes:form id="payerAddFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
                method="post">        
                <table id="PayerTable" >  
                    <%  if (UserUtil.isBankGroup()) {%>
                    <tr>
                        <th>業者代號<span id="mustKeyInStar">**</span></th>
                        <td colspan="3">
                            <div id="findGroupNoImg1"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
                                <input id="groupNo" maxlength="12" name="groupNo" type="text" size="12"/>                                
                      	<span id="qryFormatDefinition.group.groupName2.span"><c:out value="${actionBean.qryGroup.groupName }"/></span>
                     
                        </td>                         
                       
                                                          
                    </tr>
                    <%
                        } else {
                    %>                             
                    <% }%> 
                    <tr>     
                        <th>客戶編號<span id="mustKeyInStar">**</span></th>
                        <td>
                            <stripes:text id="payerNo" name="resultPayer.payerNo" size="15" maxlength="20" />
                        </td> 
                        <th>姓名<span id="mustKeyInStar">**</span></th>
                        <td>
                            <stripes:text id="payerName" name="resultPayer.payerName" size="15" maxlength="20" />
                        </td>                                 
                    </tr>
                                          
                    <tr>
                        <th>E-MAIL</th>
                        <td colspan="3">
                            <stripes:text id="payerEmail" name="resultPayer.payerEmail" size="50" maxlength="50" />
                        </td>                        
                    </tr>                
                    <tr>
                        <th>電話</th>
                        <td>
                            <stripes:text id="payerTelNo" name="resultPayer.payerTelNo" size="15" maxlength="20" />
                        </td>
                        <th>手機號碼</th>
                        <td>
                            <stripes:text id="payerCellNo" name="resultPayer.payerCellNo" size="15" maxlength="10" />
                        </td>                        
                    </tr>  
                    <tr>
                        <th>坪數</th>
                        <td>
                            <stripes:text id="levelGround" name="resultPayer.levelGround" size="15" maxlength="5" />
                        </td>
                        <th>車位數</th>
                        <td>
                            <stripes:text id="parkingCount" name="resultPayer.parkingCount" size="15" maxlength="2" />
                        </td>                        
                    </tr> 
                    <tr>
                        <th>門牌號碼</th>
                        <td colspan="3">
                            <stripes:text id="houseNo" name="resultPayer.houseNo" size="50" maxlength="50" />                         
                        </td>
                    </tr>    
                    <tr>
                        <th>聯絡地址</th>
                        <td colspan="3">
                            <stripes:text id="payerAddress" name="resultPayer.payerAddress" size="50" maxlength="50" />                         
                        </td>
                    </tr> 
                    <tr>
                        <th>備註</th>
                        <td colspan="3">
                            <stripes:text id="payerMemo" name="resultPayer.payerMemo" size="50" maxlength="50" />                         
                        </td>
                    </tr>                                                                                         
                    <tr>
                        <td colspan="4" class="queryFunction" align="center">
                            <stripes:button id="doSaveBtn" name="doSaveBtn" value="確認" class="formBtn"/>
                            <stripes:button id="doCloseBtn" name="doCloseBtn" value="離開" class="formBtn"/>
                        </td>
                    </tr>                   
                </table>
            </stripes:form>    
        </div>
            
        
        <div id="savePayerHiddenFormDiv" style="display: none; ">
            <stripes:form id="savePayerHiddenFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
                method="post" onsubmit="javascript: return false;">
                <%if (UserUtil.isBankGroup()) {%>
                <input type="hidden" id="hidden5.resultPayer.groupNo" name="resultPayer.group.groupNo"/>
                <%} else {%>
                <input type="hidden" id="hidden5.resultPayer.groupNo" name="resultPayer.group.groupNo" value="<%=UserUtil.getUserGroup().getGroupNo() %>"/>
                <%} %>
                  
                <input type="hidden" id="hidden5.resultPayer.payerNo" name="resultPayer.payerNo"/>
                <input type="hidden" id="hidden5.resultPayer.payerName" name="resultPayer.payerName"/>                    
                <input type="hidden" id="hidden5.resultPayer.payerEmail" name="resultPayer.payerEmail"/>
                <input type="hidden" id="hidden5.resultPayer.payerTelNo" name="resultPayer.payerTelNo"/>
                <input type="hidden" id="hidden5.resultPayer.payerCellNo" name="resultPayer.payerCellNo"/>
                <input type="hidden" id="hidden5.resultPayer.levelGround" name="resultPayer.levelGround"/>
                <input type="hidden" id="hidden5.resultPayer.parkingCount" name="resultPayer.parkingCount"/>
                <input type="hidden" id="hidden5.resultPayer.houseNo" name="resultPayer.houseNo"/>
                <input type="hidden" id="hidden5.resultPayer.payerAddress" name="resultPayer.payerAddress"/>
                <input type="hidden" id="hidden5.resultPayer.payerMemo" name="resultPayer.payerMemo"/>                
                
                <input type="hidden" id="method6" name="doPayerAddAction"/>
            </stripes:form>
        </div>
        <div id="savePayerMsgDiv" style="display: none; ">
        </div> 
        <script type="text/javascript">
        <!--
            $(document).ready(function() {
                $("[id^='paymentType-']").click(function() {
                    var paymentType = this.id.substring(12);
                    $('#hidden5\\.resultPayer\\.paymentType').val(paymentType); 
                });
                
                $("#doCloseBtn").click(function() {
                    $("#payerDiv").dialog("close");
                });
                
                $("#doSaveBtn").click(function() {
                    <%if (UserUtil.isBankGroup()) {%>
                    var groupNo = $('#groupNo').val();
                    $('#hidden5\\.resultPayer\\.groupNo').val(groupNo);
                    <%}%> 
  
                    var paymentType = $('input[name=resultPayer.paymentType]:checked').val();
                    var payerNo = $('#payerNo').val();
                    var payerName = $('#payerName').val();
                    var payerEmail = $('#payerEmail').val();
                    var payerTelNo = $('#payerTelNo').val();
                    var payerCellNo = $('#payerCellNo').val();
                    var levelGround = $('#levelGround').val();
                    var parkingCount = $('#parkingCount').val();
                    var houseNo = $('#houseNo').val();
                    var payerAddress = $('#payerAddress').val();
                    var payerMemo = $('#payerMemo').val();
                    
                    $('#hidden5\\.resultPayer\\.payerNo').val(payerNo);
                    $('#hidden5\\.resultPayer\\.payerName').val(payerName);
                    $('#hidden5\\.resultPayer\\.payerEmail').val(payerEmail);
                    $('#hidden5\\.resultPayer\\.payerTelNo').val(payerTelNo);
                    $('#hidden5\\.resultPayer\\.payerCellNo').val(payerCellNo);
                    $('#hidden5\\.resultPayer\\.levelGround').val(levelGround);
                    $('#hidden5\\.resultPayer\\.parkingCount').val(parkingCount);  
                    $('#hidden5\\.resultPayer\\.houseNo').val(houseNo); 
                    $('#hidden5\\.resultPayer\\.payerAddress').val(payerAddress); 
                    $('#hidden5\\.resultPayer\\.payerMemo').val(payerMemo);                     
                    
                    var errorMessage = '';
                    <%if (UserUtil.isBankGroup()) {%>
                    
                    if (groupNo == '') 
                        errorMessage = errorMessage + '業者代號 是必要欄位<br/>'; 
                    <%}%>                     
                   
                    if (payerNo == '') 
                        errorMessage = errorMessage + '客戶編號 是必要欄位<br/>';
                    
                    if (payerName == '') 
                        errorMessage = errorMessage + '姓名 是必要欄位<br/>';
                    
                    if (null == payerEmail || 0 == payerEmail.length){
        				
        			}
        			else if (! verifyEmail(payerEmail)){
        				errorMessage = errorMessage + "E-MAIL 格式錯誤<br/>";
        			}
                    
                    if (0 != errorMessage.length){
        				$("#ajaxErrorMessageDiv").html(errorMessage);
        				$("#ajaxErrorMessageDiv" ).dialog({  
        					title:'請修正下列錯誤' 
        					,width: 300
        					, resizable: false
        					, modal: true
        					, buttons: {
        						Ok: function() {
        							$( this ).dialog( "close" );
        						}
        					}
        				});
        				return false;
        			}          
                    
                    waitingDialog({});
                    $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
                        async : false,
                        type : 'POST',
                        data : $("#savePayerHiddenFrom").serialize(),
                        dataType : 'html',
                        success : function(data, textStatus, XMLHttpRequest){
                                $("#addPayerViewDiv").hide();
                                $("#savePayerMsgDiv" ).html(data);
                                $("#savePayerMsgDiv").show();
                            },
                        error : function(XMLHttpRequest, textStatus, errorThrown){
                            $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                            $("#ajaxErrorMessageDiv" ).dialog({  
                                title:'系統錯誤' 
                                ,width: 600
                                , resizable: false
                                , modal: true
                                , buttons: {
                                    Ok: function() {
                                        $( this ).dialog( "close" );
                                    }
                                }
                            });
                            },
                        complete: function(XMLHttpRequest, textStatus){
                            closeWaitingDialog();
                        }
                    });
                });            
            });               
        //-->
        </script>        
    </c:when>
    <c:otherwise>
            查無資料
        <script type="text/javascript">
        <!--
        $(document).ready(function() {
            $( "#payerDiv" ).dialog({  title:'繳款人資料' ,width: 600, resizable: false, modal: true  });
        });
        //-->
        </script>
    </c:otherwise>
</c:choose>    